<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Requests\Api\ClockRecord\ListRequest;
use App\Requests\Api\ClockRecord\StoreRequest;
use App\Requests\Api\ClockRecord\UpdateRequest;
use App\Service\ClockRecordService;
use Illuminate\Support\Arr;

class ClockRecordController extends Controller
{
    protected $fractal;
    protected $clockRecordService;

    public function __construct(
        ClockRecordService $clockRecordService
    ){
        $this->clockRecordService = $clockRecordService;
    }

    public function list(ListRequest $request) {
        $params = request(['page', 'status']);
        $params['per_page'] = config('app.page_number');
        $clockRecordInfo = $this->clockRecordService->list($params);
        response($clockRecordInfo);
    }

    public function store(StoreRequest $request) {
        $clockRecordInfo = $this->clockRecordService->store(request(['clock_id', 'clock_type', 'begin_time', 'begin_address', 'end_time', 'end_address', 'begin_remark', 'end_remark', 'begin_abnormal_info', 'end_abnormal_info']));
        return $clockRecordInfo;
    }

    public function update($clock_id, UpdateRequest $request) {
        $clockRecordInfo = $this->clockRecordService->update($clock_id, request(['begin_time', 'begin_address', 'end_time', 'end_address', 'begin_remark', 'end_remark', 'begin_abnormal_info', 'end_abnormal_info']));
        return $clockRecordInfo;
    }
}
